{extend name="admin@index_layout"/}
{block name="main"}
<style type="text/css">
    .childrenBody {
        background: #fff;
    }
</style>

<div class="layui-card">
    <div class="layui-card-header">食光惊喜袋列表</div>
    <div class="layui-card-body">
        <table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
    </div>
</div>
<script type="text/html" id="picTpl">

    <img style="max-width:80px; max-height:30px;" src="{{d.img}}" data-image="{{d.name}}">

</script>
<script type="text/html" id="barTool">
    <a class="layui-btn layui-btn-xs" data-open='{:url("edit")}?id={{ d.id }}' data-title="惊喜袋编辑"
       data-full="true">编辑</a>
    <a href='{:url("del",["catid"=>$catid])}?ids={{ d.id }}'
       class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
</script>



{/block}
{block name="script"}
<script>
    layui.use(['table', 'yznTable'], function () {
        // var table = layui.table,
        //     $ = layui.$,
        //     form = layui.form,
        //     table = layui.table,
        var table = layui.yznTable;

        var init = {
            table_elem: '#currentTable',
            add_url: "{:url('add',['catid'=>$catid])}",
            delete_url: "{:url('del',['catid'=>$catid])}",
            modify_url: '{:url("listorder",["catid"=>$catid])}',
        };
        var proviec = {:json_encode($proviec)};
        table.render({
            init: init,
            id: 'currentTable',
            elem: '#currentTable',
            url: '{:url("index")}',
            // searchFormTpl:,
            toolbar: ['refresh',
                // [{
                //     text: '添加',
                //     url: init.add_url,
                //     method: 'open',
                //     icon: 'iconfont icon-add',
                //     class: 'layui-btn layui-btn-normal layui-btn-sm',
                //     extend: 'data-full="true"',
                // }],
            ],
            cols: [
                [
                    {field: 'id', width: '4%', title: 'ID', search: false},
                    {
                        field: 'province',
                        align: "center",
                        width: '15%',
                        title: '省',
                        hide: true,
                        selectList: proviec
                    },
                    {field: 'city', align: "center", width: '15%', title: '市',hide: true,
                        selectList: {}},
                    {field: 'business_name', align: "center", width: '15%', title: '商家名称'},
                    {field: 'address_detail', align: "center", width: '20%', title: '商家地址',search: false},

                    {field: 'people_name', align: "center", width: '10%', title: '负责人', search: false},
                    {field: 'phone', align: "center", width: '10%', title: '联系电话', search: false},
                    {field: 'name', align: "center", width: '15%', title: '惊喜袋名称'},
                    {field: 'phone', align: "center", width: '10%', title: '图片', templet: '#picTpl', search: false},
                    {field: 'price', align: "center", width: '10%', title: '价格', search: false},
                    {field: 'old_price', align: "center", width: '10%', title: '原价', search: false},
                    {field: 'weight', align: "center", width: '10%', title: '重量（g）', search: false},
                    {field: 'co2', align: "center", width: '10%', title: '碳排放量', search: false},
                    {
                        field: 'status', align: "center", width: '8%', title: '状态', templet: function (d) {
                            if (d.status == 1) {
                                return '<span style="color: #00B7EE">已上架</span>';
                            } else if (d.status == 2) {
                                return '<span style="color: green">审核中</span>';
                            } else if (d.status == 3) {
                                return '<span style="color:red ">未通过</span>';
                            } else if (d.status == 4) {
                                return '<span style="color: #1d1e22 ">仓库中</span>';
                            } else {
                                return '<span>未知</span>';
                            }
                        },  selectList: {1: '已上架',4:'仓库中'}
                    },
                    {field: 'create_time', align: "center", width: '20%', title: '创建时间', search: false},
                    {fixed: 'right', align: "center", width: '10%', title: '操作', toolbar: '#barTool'}
                ]
            ],
            page: {}
        });
        yznTable.bindevent();
        selectElement = document.getElementById('c-province');
        selectElement.setAttribute("lay-filter", "c-province");
        form1();
        selectElement2 = document.getElementById('searchFieldset_currentTable');
        selectElement2.classList.remove("layui-hide");
        var element = document.getElementById('layui-input-search');
        element.parentNode.removeChild(element);
    });
    function form1(){
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(c-province)', function (data) {
                console.log(data.value);
                $.ajax({
                    type: "POST",//规定传输方式
                    url: "{:url('getc_cate')}",//提交URL
                    data: {'id':data.value},//提交的数据
                    success: function(result){
                        if(result.code == 200){
                            $("#c-city").empty();
                            var str = "<option value>- 全部 -</option>";
                            $.each(result.data, function(i, val){
                                str += '<option value='+val.id+'>'+val.name+'</option>'
                            });
                            $("#c-city").append(str);
                            layui.form.render('select');
                        }
                    },
                    error: function() {
                        alert("获取信息失败")
                    }
                });
            })
        });
    }
</script>
{/block}